/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

/**
 *
 * @author Salm
 */
class SwitchableMultiRedis implements MultiRedis {
    private final MultiRedis mRedis;
    private final ThreadLocal<Integer> defaultIndex = new ThreadLocal();

    public SwitchableMultiRedis(MultiRedis mRedis) {
        this.mRedis = mRedis;
    }

    @Override
    public db.Redis Redis() {
        Integer index = defaultIndex.get();
        if (index == null)
        {
            index = 0;
        }
        
        return mRedis.Redis(index);
    }

    @Override
    public db.Redis Redis(int idx) {
        return mRedis.Redis(idx);
    }
    
    public void changeDefault(Integer index)
    {
        defaultIndex.set(index);
    }
    
    public Integer getCurrentDefault()
    {
        return defaultIndex.get();
    }
}
